package hle.com;
import java.sql.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Solution {
    List<Integer> path = new ArrayList<Integer>();
    List<List<Integer>> result = new ArrayList<List<Integer>>();

    public List<List<Integer>> subsetsWithDup(int[] nums) {
    	result.add(new ArrayList<>());
    	Arrays.sort(nums);
        dfs(0, nums);
        return result;
    }

    public void dfs(int start, int[] nums) {
    	if (start >= nums.length) return;
    	for (int i = start; i < nums.length; i++) {
    		if ( i > start && nums[i] == nums[i - 1]) continue;
    		path.add(nums[i]);
    		result.add(new ArrayList<>(path));
    		dfs(i + 1, nums);
    		path.remove(path.size() - 1);
    	}
    }
    
    public static void main(String[] args) {
    	int[] num = new int[] {1,2,2};
    	System.out.println(new Solution().subsets(num));
	}
}